source(here::here("code/load.R"))

cols <- colnames(read_excel(here("data/meta_analyses_raw/Phi2016/dataset.xls")))

here("data/meta_analyses_raw/Phi2016/dataset.xls") |>
    read_excel(skip = 1) |>
    setNames(cols) |>
    # funnel plots in the paper only who 4 categories of the DV, not "other" or missing.
    filter(!is.na(Revenues_expenditures_fiscalbalance),
           Revenues_expenditures_fiscalbalance != "other") |>
    mutate(
        meta_id = "Phi2016",
        subfield = "PE",
        question = "whether a link between elections and government budgets exists",
        overall_effect = "no", 
        # if we lack a t but have a coefficient and se, fill in the t
        election_t = if_else(
            is.na(election_t),
            election_beta / election_se,
            election_t),
        # calculate parital correlation coefficients and SEs from t and df
        partial_corr = election_t / sqrt(election_t^2 + df),
        partial_corr_se = sqrt((1 - partial_corr) / df)) |>
    select(meta_id,
        subfield,
        question,
        study_id = author,
        study_year = year,
        study_journal = journal,
        sample_size = obs,
        estimate = partial_corr,
        dv = Revenues_expenditures_fiscalbalance,
        std.error = partial_corr_se,
        overall_effect) |>
    write_csv(here("data/meta_analyses_clean/Phi2016.csv"))
    
